package com.webproject.entity;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;


public class Rules {

	private Map<String, String> opMap;
	private String field;
	private String op;
	private String data;
	public Rules(){
		opMap=new HashMap<String, String>();
		opMap.put("eq", "=");  
        opMap.put("ne", "<>");  
        opMap.put("lt", "<");  
        opMap.put("le", "<=");  
        opMap.put("gt", ">");  
        opMap.put("ge", ">=");  
        opMap.put("bw", "LIKE");  
        opMap.put("bn", "NOT LIKE");  
        opMap.put("in", "=");  
        opMap.put("ni", "<>");  
        opMap.put("ew", "LIKE");  
        opMap.put("en", "NOT LIKE");  
        opMap.put("cn", "LIKE");  
        opMap.put("nc", "NOT LIKE");
	}
	public String getField() {
		return field;
	}
	public void setField(String field) {
		this.field = field;
	}
	public String getOp() {
		return op;
	}
	public void setOp(String op) {
		this.op = opMap.get(op);
	}
	public String getData() {
		return data;
	}
	public void setData(String data) {
		this.data = newData(data);
	}
	private String newData(String data){
		String d=data;
		try {
			d=new String(data.getBytes("iso8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String newData="";
		if(getOp().equals("LIKE") || getOp().equals("NOT LIKE")){
			newData="%"+d+"%";
		}else if (getOp().equals("IN") || getOp().equals("NOT IN")){
			newData="("+d+")";
		}else{
			newData=d;
		}
		return newData;
	}
}
